package com.inkrl.order.controller;

import com.inkrl.order.service.OrderService;
import com.jt.common.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("order")
    public SysResult queryOrder(HttpServletRequest request){
        String token = request.getHeader("token");
        List<Map<String,Object>> orderItem = orderService.queryOrder(token);
        return SysResult.build(200,"查看订单",orderItem);
    }
    @GetMapping("orders")
    public SysResult queryDetails(HttpServletRequest request){
        String token = request.getHeader("token");
        List<Map<String,Object>> order = orderService.queryDetails(token);
        return SysResult.build(200,"订单详情",order);
    }
    @PostMapping("order")
    public SysResult addOrder(HttpServletRequest request,String id){
        String token = request.getHeader("token");
        Map<String,Object> map = orderService.addOrder(token,id);
        return SysResult.build(200,"确认订单",map);
    }
}
